package com.example.user.controller;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.user.domain.classroom.vo.ClassroomDetailVO;
import com.example.user.domain.classroom.dto.ClassroomQueryDTO;
import com.example.user.domain.classroom.dto.BuyClassroomSaveDTO;
import com.example.user.domain.classroom.vo.ClassroomVO;
import com.example.user.service.IClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/classroom")
public class ClassroomController extends BaseController {

    @Autowired
    private IClassroomService classroomService;

    @GetMapping("/list")
    public TableDataInfo list(ClassroomQueryDTO classroomQueryDTO) {
        return getTableDataInfo(classroomService.list(classroomQueryDTO));
    }


    @GetMapping("/availableClass")
    public TableDataInfo availableClass(ClassroomQueryDTO classroomQueryDTO) {
        return getTableDataInfo(classroomService.availableClass(classroomQueryDTO));
    }

    @GetMapping("/classroomDetails")
    public R<ClassroomDetailVO> classroomDetails(Long classroomId) {
        return R.ok(classroomService.classroomDetails(classroomId));
    }

    @GetMapping("/enrolledInAClass")
    public R<Boolean> enrolledInAClass(Long classroomId) {
        return R.ok(classroomService.enrolledInAClass(classroomId));
    }

    @PutMapping("/buyClassroom")
    public R<Void> buyClassroom(BuyClassroomSaveDTO buyClassroomSaveDTO ) {
        return toR(classroomService.buyClassroom(buyClassroomSaveDTO));
    }

    @GetMapping("/myClassroom")
    public R<ClassroomVO> myClassroom() {
        return R.ok(classroomService.myClassroom());
    }
}
